include ../../cross.mk


ELF_LED_ON  = led_on
OBJS_LED_ON = crt.o led_on.o
BIN_LED_ON  = led_on.bin
DIS_LED_ON  = led_on.dis

ELF_LED_BLINK  = led_blink
OBJS_LED_BLINK = crt.o led_blink.o
BIN_LED_BLINK  = led_blink.bin
DIS_LED_BLINK  = led_blink.dis

ELF_LED_FLOW  = led_flow
OBJS_LED_FLOW = crt.o led_flow.o
BIN_LED_FLOW  = led_flow.bin
DIS_LED_FLOW  = led_flow.dis

ELF_LED_BUTTON  = led_button
OBJS_LED_BUTTON = crt.o led_button.o
BIN_LED_BUTTON  = led_button.bin
DIS_LED_BUTTON  = led_button.dis

ALL =  $(ELF_LED_ON) $(BIN_LED_ON) $(DIS_LED_ON)
ALL += $(ELF_LED_BLINK) $(BIN_LED_BLINK) $(DIS_LED_BLINK)
ALL += $(ELF_LED_BUTTON) $(BIN_LED_BUTTON) $(DIS_LED_BUTTON)
ALL += $(ELF_LED_FLOW) $(BIN_LED_FLOW) $(DIS_LED_FLOW)
CLEAN =  clean_led_on 
CLEAN += clean_led_blink
CLEAN += clean_led_button
CLEAN += clean_led_flow

.PHONY: all
.PHONY: clean

all: $(ALL)
clean: $(CLEAN)


#-Ttext指定代码的启示地址为0x00000000
$(ELF_LED_ON): $(OBJS_LED_ON)
	$(LD) -Ttext 0x00000000 $(OBJS_LED_ON) -o $(ELF_LED_ON)

$(BIN_LED_ON): $(ELF_LED_ON)
	$(OBJCOPY) -O binary -S $(ELF_LED_ON) $(BIN_LED_ON)

$(DIS_LED_ON):
	$(OBJDUMP) -D -m arm $(ELF_LED_ON) > $(DIS_LED_ON)


#led blink like a star
$(ELF_LED_BLINK): $(OBJS_LED_BLINK)
	$(LD) -Ttext 0x00000000 $(OBJS_LED_BLINK) -o $(ELF_LED_BLINK)

$(BIN_LED_BLINK): $(ELF_LED_BLINK)
	$(OBJCOPY) -O binary -S $(ELF_LED_BLINK) $(BIN_LED_BLINK)

$(DIS_LED_BLINK):
	$(OBJDUMP) -D -m arm $(ELF_LED_BLINK) > $(DIS_LED_BLINK)

#leds like water flow
$(ELF_LED_FLOW): $(OBJS_LED_FLOW)
	$(LD) -Ttext 0x00000000 $(OBJS_LED_FLOW) -o $(ELF_LED_FLOW)

$(BIN_LED_FLOW): $(ELF_LED_FLOW)
	$(OBJCOPY) -O binary -S $(ELF_LED_FLOW) $(BIN_LED_FLOW)

$(DIS_LED_FLOW):
	$(OBJDUMP) -D -m arm $(ELF_LED_FLOW) > $(DIS_LED_FLOW)

#button control leds
$(ELF_LED_BUTTON): $(OBJS_LED_BUTTON)
	$(LD) -Ttext 0x00000000 $(OBJS_LED_BUTTON) -o $(ELF_LED_BUTTON)

$(BIN_LED_BUTTON): $(ELF_LED_BUTTON)
	$(OBJCOPY) -O binary -S $(ELF_LED_BUTTON) $(BIN_LED_BUTTON)

$(DIS_LED_BUTTON):
	$(OBJDUMP) -D -m arm $(ELF_LED_BUTTON) > $(DIS_LED_BUTTON)



%.o: %.c
	$(CC) -c $< -o $@

%.o: %.S
	$(CC) -c $< -o $@


clean_led_on:
	rm -rf $(BIN_LED_ON) $(DIS_LED_ON) $(ELF_LED_ON) $(OBJS_LED_ON) 

clean_led_blink:
	rm -rf $(BIN_LED_BLINK) $(DIS_LED_BLINK) $(ELF_LED_BLINK) $(OBJS_LED_BLINK) 

clean_led_flow:
	rm -rf $(BIN_LED_FLOW) $(DIS_LED_FLOW) $(ELF_LED_FLOW) $(OBJS_LED_FLOW) 

clean_led_button:
	rm -rf $(BIN_LED_BUTTON) $(DIS_LED_BUTTON) $(ELF_LED_BUTTON) $(OBJS_LED_BUTTON) 




